// 数据
var list = [
    {
        company_id: 101,
        company_name: '高地铁',
        company_person: '孙明',
        company_phone: '13356495687',
        company_mail: '1@1.com',
        carry: false,
        audit_state: '审核通过',
        apply_time: 1510031238293,
        operation: '审核',
    },
    {
        company_id: 102,
        company_name: '高地铁',
        company_person: '孙明',
        company_phone: '13356495687',
        company_mail: '1@1.com',
        carry: false,
        audit_state: '申请中',
        apply_time: 1510031238293,
        operation: '审核',
    },
    {
        company_id: 103,
        company_name: '高地铁',
        company_person: '孙明',
        company_phone: '13356495687',
        company_mail: '1@1.com',
        carry: false,
        audit_state: '申请中',
        apply_time: 1510031238293,
        operation: '审核',
    },
    {
        company_id: 104,
        company_name: '高地铁',
        company_person: '孙明',
        company_phone: '13356495687',
        company_mail: '1@1.com',
        carry: true,
        audit_state: '申请中',
        apply_time: 1510031238293,
        operation: '审核',
    },
    {
        company_id: 105,
        company_name: '高地铁',
        company_person: '孙明',
        company_phone: '13356495687',
        company_mail: '1@1.com',
        carry: false,
        audit_state: '申请中',
        apply_time: 1510031238293,
        operation: '审核',
    },
    {
        company_id: 106,
        company_name: '高地铁',
        company_person: '孙明',
        company_phone: '13356495687',
        company_mail: '1@1.com',
        carry: false,
        audit_state: '申请中',
        apply_time: 1510031238293,
        operation: '审核',
    },
    {
        company_id: 107,
        company_name: '高地铁',
        company_person: '孙明',
        company_phone: '13356495687',
        company_mail: '1@1.com',
        carry: true,
        audit_state: '申请中',
        apply_time: 1510031238293,
        operation: '审核',
    },
    {
        company_id: 108,
        company_name: '高地铁',
        company_person: '孙明',
        company_phone: '13356495687',
        company_mail: '1@1.com',
        carry: false,
        audit_state: '申请中',
        apply_time: 1510031238293,
        operation: '审核',
    },
    {
        company_id: 109,
        company_name: '高地铁',
        company_person: '孙明',
        company_phone: '13356495687',
        company_mail: '1@1.com',
        carry: true,
        audit_state: '申请中',
        apply_time: 1510031238293,
        operation: '审核',
    },
    {
        company_id: 110,
        company_name: '高地铁',
        company_person: '孙明',
        company_phone: '13356495687',
        company_mail: '1@1.com',
        carry: true,
        audit_state: '审核失败',
        apply_time: 1510031238293,
        operation: '审核',
    }
]
var html = '';
list.forEach(value => {
    html += `<tr>
           <td>${value.company_name}</td>
           <td>${value.company_person}</td>
           <td>${value.company_phone}</td>
           <td>${value.company_mail}</td>
           <td>${value.carry ? '是' : '否'}</td>
           <td>${value.audit_state}</td>
           <td>${date(value.apply_time)}</td>
           <td><a href="info.html?id=${value.company_id}">${value.operation}</a> </td>
        </tr>`
})
$('.list-data').html(html)
function check_Pending() {
    $('.check').attr('style', 'background-color:#d7342e;color:#fff');
    console.log('待审核')
    // api(path,param)
}
function checked() {
    $('.check').attr('style', 'background-color:#fff;color:#000');
    console.log('已审核')
    // api(path,param)

}
check_Pending()

var data = list.filter(item => item.company_id == getUrlParam('id'))
$('#info-name').val(data[0].company_name)
$('#info-person').val(data[0].company_person)
$('#info-phone').val(data[0].company_phone)
$('#info-mail').val(data[0].company_mail)
$('#info-carry').prop('checked', data[0].carry)
if (data[0].carry) {
    $('#info-cause').attr('style', 'display:none')
}
if (data[0].audit_state == '申请中') {
    $('.lose').attr('style', 'display:none')
    $('.succeed').attr('style', 'display:none')
}
else if (data[0].audit_state == '审核通过') {
    $('.lose').attr('style', 'display:none')
    $('.apply').attr('style', 'display:none')
}
else if (data[0].audit_state == '审核失败') {
    $('.apply').attr('style', 'display:none')
    $('.succeed').attr('style', 'display:none')
}
// 接口
function api(path, param) {
    $.ajax({
        url: path,
        type: 'post',
        data: {
            param
        },
        success: function (data) {
            console.log(data)

        },
        error: function () {

        }
    });
}
// 图片放大
function magnify(event) {
    $('.show-img').attr('src', event.target.currentSrc)
    $('.model').removeClass('hide')
    document.querySelector('.show-img').style.height=400+'px'
    document.querySelector('.show-img').style.width=400+'px'
    document.querySelector('.show-img').style.zoom=100+'%'
    document.querySelector('.dragAble').style.left=(window.innerWidth-400)/2+'px'
    document.querySelector('.dragAble').style.top=(window.innerHeight-400)/2+'px'
    document.querySelector('.close-img').style.marginLeft=400-30+'px'
}
// 获取参数
function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return decodeURI(r[2]); return null; //返回参数值
}
// var company_cause=document.querySelector('#info-cause')
// 同意
function agree() {

}
// 不同意
function disagree() {
    if ($('#lose-cause').val() == '') {
        $('#oppose-btn').attr('data-am-modal', "{target: '#my-alert'}")
    }
    else {
        $('#oppose-btn').attr('data-am-modal', null)
    }

}
// 时间
function date(time) {
    var now_Date = new Date(time)
    var y = now_Date.getFullYear()
    var m = now_Date.getMonth() + 1
    var d = now_Date.getDate()
    return y + '-' + m + '-' + d
}
/*鼠标将图片在相应的div自由拖动*/
drag = 0;
move = 0;
var ie = document.all;
var nn6 = document.getElementById && !document.all;
var isdrag = false;
var y, x;
var oDragObj;
var pic_width, pic_height, pic_zoom;
var divleft, divtop;

function moveMouse(e) {
    if (isdrag) {
        oDragObj.style.top = (nn6 ? nTY + e.clientY - y : nTY + event.clientY - y) + "px";
        oDragObj.style.left = (nn6 ? nTX + e.clientX - x : nTX + event.clientX - x) + "px";
        return false;
    }
}
function initDrag(e) {
    var oDragHandle = nn6 ? e.target : event.srcElement;
    var topElement = "HTML";
    while (oDragHandle.tagName != topElement && oDragHandle.className != "dragAble") {
        oDragHandle = nn6 ? oDragHandle.parentNode : oDragHandle.parentElement;
    }
    if (oDragHandle.className == "dragAble") {
        isdrag = true;
        oDragObj = oDragHandle;
        nTY = parseInt(oDragObj.style.top + 0);
        y = nn6 ? e.clientY : event.clientY;
        nTX = parseInt(oDragObj.style.left + 0);
        x = nn6 ? e.clientX : event.clientX;
        document.onmousemove = moveMouse;
        return false;
    }
}
$(document).ready(function () {
    if (window.addEventListener) {
        window.addEventListener('DOMMouseScroll', wheel, false);//给firefox添加鼠标滚动事件，因为火狐没有wheel事件
    }
});

function wheel(event) {
    if (!event) /**//* For IE. */ {
        event = window.event;
    }
    else if (event.detail) {
        var height1 = $("#images1").attr("height");

        if (!height1) {
            height1 = height1.substring(0, height1.length - 2);

        }
        var width1 = $("#images1").attr("width");

        if (!width1) {
            width1 = width1.substring(0, width1.length - 2);

        }
        if (event.detail < 0) {
            var temp1 = parseInt(height1) * 1.2;
            var temp2 = parseInt(width1) * 1.2;


        } else {
            var temp1 = parseInt(height1) / 1.2;
            var temp2 = parseInt(width1) / 1.2;
        }

        $("#images1").attr("height", temp1 + "px");

        $("#images1").attr("width", temp2 + "px");
    }
}
/*非Firefox的主流浏览器*/
function bbimg(o) {
    var zoom = parseInt(o.style.zoom, 10) || 100;
    zoom += event.wheelDelta / 12;
    if (zoom >= 80) 
    {o.style.zoom = zoom + '%';
    document.querySelector('.close-img').style.marginLeft=4*zoom-30+'px'
    }
    return false;
}
document.onmousedown = initDrag;
document.onmouseup = new Function("isdrag=false");
//  双击图片恢复到原图
function realsize() {
  $('.model').addClass('hide')
}
